
import java.net.*;

/**
 * @author AMPM
 * 
 * This class represents a simple TCP server able to serve
 * a simple TCP client. When a client connects, it is served
 * in a separate thread running an instance of ClientHandler
 *
 */

public class SimpleTcpServer {

    public static void main (String args[]) throws Exception{
    	// the server socket object is created
    	int serverPort = 7896;
    	ServerSocket serverSocket = new ServerSocket( serverPort );
    	
    // when started, the server listens infinitely for new client connections
    while ( true ) 
    {
    	// the server socket starts listening for connections. When a connection
    	// is requested from a client, a socket is returned
    	Socket socket = serverSocket.accept();
    	
    	// the client is handled by the ClientHandler object in a separate thread
    	SaraClientHandler handler = new SaraClientHandler(socket);
    	new Thread(handler).start();

    }
  }
}